package org.dearbinge.client.test.openapi;



import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;

/**
 * Hello world!
 *
 */
@EnableSwagger2
@SpringBootApplication(scanBasePackages = "com.dearbinge")
@ImportResource({ "classpath:applicationContext.xml", "dubbo-services.xml" })
@EnableScheduling
public class App {
	public static void main(String[] args){
/*
		CloseableHttpClient httpclient = HttpClients.createDefault();
		String apiUrl = "http://localhost:8080/syncParkingBasicData";
		HttpPost httpPost = new HttpPost(apiUrl);
		List<NameValuePair> listPair = new ArrayList<NameValuePair>();
		// 填入各个表单域的值
		listPair.add(new BasicNameValuePair("secret_key", "1"));
		listPair.add(new BasicNameValuePair("method", "dearbinge.parkingbasicdata.sync"));
		httpPost.setEntity(new UrlEncodedFormEntity(listPair));
		UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(listPair, "UTF-8");
		httpPost.setEntity(formEntity);
		CloseableHttpResponse response = httpclient.execute(httpPost);
		try {
			System.out.println(response.getStatusLine());
			HttpEntity entity = response.getEntity();
			// do something useful with the response body
			// and ensure it is fully consumed
			String result = EntityUtils.toString(entity, "UTF-8");
			System.out.println(result);
			JsonNode jsonNode = JsonUtil.getJsonNodeByKey(result, Constants.ERROR_RESPONSE);
			if (jsonNode != null) {
				System.out.println(jsonNode.toString());
			}
			EntityUtils.consume(entity);
		} finally {
			response.close();
		}*/
		SpringApplication.run(App.class, args);
	}


//	  @Bean
//	    public EmbeddedServletContainerFactory servletContainer() {
//	        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
//	            @Override
//	            protected void postProcessContext(Context context) {
//	                SecurityConstraint constraint = new SecurityConstraint();
//	                constraint.setUserConstraint("CONFIDENTIAL");
//	                SecurityCollection collection = new SecurityCollection();
//	                collection.addPattern("/*");
//	                constraint.addCollection(collection);
//	                context.addConstraint(constraint);
//	            }
//	        };
//	        tomcat.addAdditionalTomcatConnectors(httpConnector());
//	        return tomcat;
//	    }
//
//	    @Bean
//	    public Connector httpConnector() {
//	        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
//	        connector.setScheme("http");
//	        //Connector监听的http的端口号
//	        connector.setPort(80);
//	        connector.setSecure(false);
//	        //监听到http的端口号后转向到的https的端口号
//	        connector.setRedirectPort(8050);
//	        return connector;
//	    }
}
